﻿using Entity;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;

namespace YunProject.Controllers.Base
{
    public class BaseController : Controller
    {
        SysFramework.SystemManagement sysBLL;
        public BaseController()
        {
            sysBLL = new SysFramework.SystemManagement();
        }
        private string GetCookieString()
        {
            var claims = User.Claims;
            if (claims != null && claims.Count()>0)
            {
                string enCookie = claims.Where(c => c.Type == "userCookie").FirstOrDefault().Value;
                return enCookie;
            }
            return "";
        }
        internal JObject LoginInfo()
        {
            string cookieStr = this.GetCookieString();
            if (!string.IsNullOrWhiteSpace(cookieStr))
            {
               return sysBLL.CheckLoginCookie(cookieStr);
            }
            return null;
        }
        [HttpPost]
        public JsonResult GetLoginUser()
        {
            var userObj = this.LoginInfo();
            ReturnResult rsl = new ReturnResult();
            rsl.Result = true;
            rsl.Data =JsonConvert.SerializeObject(userObj);
            return Json(rsl);
        }
    }
}
